package xcu.lxj.nettychat.user.service.Impl;

import cn.hutool.core.bean.BeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import xcu.lxj.nettychat.common.domain.vo.response.CursorPageBaseResp;
import xcu.lxj.nettychat.user.dao.UserDao;
import xcu.lxj.nettychat.user.domain.entity.User;
import xcu.lxj.nettychat.user.domain.vo.request.FuzzyMatchCursorPageReq;
import xcu.lxj.nettychat.user.domain.vo.response.UserInfoResp;
import xcu.lxj.nettychat.user.service.inter.UserService;

import java.util.List;

/**
 * @Author XinJian Lei
 * @Date 2024/10/2 17:09
 * @Version 1.0
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    UserDao userDao;

    @Override
    public UserInfoResp getUserInfo(Long uid) {
        User user = userDao.getById(uid);
        UserInfoResp userInfoResp = new UserInfoResp();
        BeanUtil.copyProperties(user,userInfoResp);
        return userInfoResp;
    }

    @Override
    public CursorPageBaseResp<UserInfoResp> getUserInfoByName(FuzzyMatchCursorPageReq request) {
        String name  = request.getContent();

        CursorPageBaseResp<User> cursorPageByName = userDao.getCursorPageByName(request, name);

        List<UserInfoResp> list = cursorPageByName.getList().stream().map(user -> {
            UserInfoResp userInfoResp = new UserInfoResp();
            BeanUtil.copyProperties(user, userInfoResp);
            return userInfoResp;
        }).toList();
        return  CursorPageBaseResp.init(cursorPageByName, list);
    }
}
